const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

function  randomNum(Min, Max){
  var Range = Max - Min;
  var Rand = Math.random();
  var num = Min + Math.round(Rand * Range);
  return num;
}
function checkData(data) {
  if (!(/^([1-9]\d*|0)(\.\d{1,2})?$/.test(data)) && !isNaN(data) && !typeof (data) == "undefined") {
    return false;
  } else {
    return true;
  }
}


module.exports = {
  formatTime: formatTime,
  randomNum:randomNum,
  checkData: checkData
}
